<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改药物管理')" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-medicine-edit" th:object="${sysAppMedicine}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">
				<label class="col-sm-3 control-label">药物分类：</label>
				<div class="col-sm-8">
					<select name="medicineClass" class="form-control m-b" th:with="type=${@dict.getType('sys_medicine_class')}">
	                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictLabel}" th:field="*{medicineClass}"></option>
	                </select>
				</div>
			</div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">药物名称：</label>
                <div class="col-sm-8">
                    <input name="medicineName" id = "medicineName" th:field="*{medicineName}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">排序：</label>
                <div class="col-sm-8">
                    <input name="ord" th:field="*{ord}" class="form-control" type="number">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">启用状态：</label>
                 <div class="col-sm-9">
                 	<label class="radio-box">
				        <input type="radio" value="1" th:field="*{state}" id="optionsRadios2" name="state">启用</label>
				    <label class="radio-box">
				        <input type="radio" value="0" th:field="*{state}" id="optionsRadios1" name="state">不启用</label>
				    
				</div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">药物描述：</label>
                <div class="col-sm-8">
                    <input  id="medicineDescribe" name="medicineDescribe" th:field="*{medicineDescribe}" type="hidden">
                    <div id="editor" class="summernote"></div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">备注信息：</label>
                <div class="col-sm-8">
                    <input name="remark" id = "remark" th:field="*{remark}" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: summernote-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/medicine";
        $("#form-medicine-edit").validate({
            focusCleanup: true
        });
        
        $(function() {
		    $('.summernote').summernote({
		    	placeholder: '请输入文章内容',
		    	height : 192,
				lang : 'zh-CN',
				followingToolbar: false,
				callbacks: {
	                onImageUpload: function (files) {
	                    sendFile(files[0], this);
	                }
	            }
		    });
		    var content = $("#medicineDescribe").val();
		    $('#editor').summernote('code', content);
	    });
	    
	    // 上传文件
	    function sendFile(file, obj) {
	        var data = new FormData();
	        data.append("file", file);
	        $.ajax({
	            type: "POST",
	            url: ctx + "common/upload",
	            data: data,
	            cache: false,
	            contentType: false,
	            processData: false,
	            dataType: 'json',
	            success: function(result) {
	                if (result.code == web_status.SUCCESS) {
	                	$(obj).summernote('editor.insertImage', result.url, result.fileName);
					} else {
						$.modal.alertError(result.msg);
					}
	            },
	            error: function(error) {
	                $.modal.alertWarning("图片上传失败。");
	            }
	        });
	    }

        function submitHandler() {
            if ($.validate.form()) {
            	var sHTML = $('.summernote').summernote('code');
            	debugger
				$("#medicineDescribe").val(sHTML);
                $.operate.save(prefix + "/edit", $('#form-medicine-edit').serialize());
            }
        }
    </script>
</body>
</html>